#include<bits/stdc++.h>
using namespace std;
namespace IO{
    template<typename T>inline void read(T &x){
        x=0;int f=1;char c=getchar();
        while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
        while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
        x*=f;
    }
    const int BUF=1<<21;
    char buf[BUF],ctop,cstk[32];int plen;
    #define flush() fwrite(buf,1,plen,stdout),plen=0
    inline void pc(char c){
        buf[plen++]=c;
        if(plen==BUF) flush();
    }
    template<typename T>inline void print(T x){
        if(!x){pc(48);return;}
        if(x<0) x=~x+1,pc('-');
        while(x) cstk[++ctop]=48+x%10,x/=10;
        while(ctop) pc(cstk[ctop--]);
    }
}
using namespace IO;
int n,a[1145],b[1145],ans;
map<vector<int>,bool> vis;
vector<int> v;
void dfs(int x,int i,int j){
    if(x==2*n-2){
        if(!vis[v]){
            ++ans;
            vis[v]=1;
        }return;
    }
    if(n-i+1>=2){
        v[x]=b[j];
        dfs(x+1,i+1,j);
    }
    if(n-j+1>=2){
        v[x]=a[i];
        dfs(x+1,i,j+1);
    }
}
int main(){
    freopen("zha.in","r",stdin);
    freopen("zha.out","w",stdout);
    cin>>n;
    for(int i=1;i<=n;++i) cin>>a[i];
    for(int i=1;i<=n;++i) cin>>b[i];
    v.resize(2*n-2);
    dfs(0,1,1);
    print(ans),pc('\n');
    flush();
    return 0;
}